import React, { useState } from 'react'

export default function CounterHook() {
    //对返回的数组，做一个结构, 数组结构语法
    const [count, setCount] = useState(0);
    return (
        <div>
            <h2>当前计数：{count}</h2>
            <button onClick={e => setCount(count + 1 )}>+1</button>
            <button onClick={e => setCount(count - 1 )}>-1</button>
            {/* 这里可以获取前一次的值，然后对前一次的值进行操作 */}
            <button onClick={e => setCount((prevCount) => prevCount + 10 )}>+10</button>
        </div>
    )
}
